﻿// ----------------------------------------------------------------------------
//  Copyright (C) 成都联宇创新科技有限公司 版权所有。 
//      
//  文件名：ICryptoService.cs
//  文件功能描述：
//  创建标识：骆智慧 2016/03/02 23:28
//     
//  修改标识：骆智慧  2016/03/10/06:40
//  修改描述：
//  ----------------------------------------------------------------------------

#region 导入名称空间

using System.Text;

#endregion

namespace LightWork.Cryptography
{
    /// <summary>
    /// 加解密服务接口
    /// </summary>
    public interface ICryptoService
    {
        /// <summary>
        /// 默认密码
        /// </summary>
        byte[] DefaultPassword { get; set; }

        /// <summary>
        /// 默认盐值
        /// </summary>
        byte[] DefaultSalt { get; set; }


        /// <summary>
        /// 默认字符串编码
        /// </summary>
        Encoding DefaultEncoding { get; set; }

        /// <summary>
        /// 加密数据
        /// </summary>
        /// <param name="plaintext">明文</param>
        /// <param name="password">用于派生密钥的密码</param>
        /// <param name="salt">用于派生密钥的密钥salt</param>
        /// <param name="iterations">操作的迭代数</param>
        /// <remarks>salt 大小必须等于或大于 8 字节，并且迭代次数必须大于零。 建议的最小迭代次数为 1000</remarks>
        /// <returns></returns>
        byte[] Encrypt(byte[] plaintext, byte[] password, byte[] salt, int iterations);

        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="plaintext">明文</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        string Encrypt(byte[] plaintext, byte[] password);

        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="plaintext">明文</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        string Encrypt(string plaintext, string password);

        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="plaintext">明文</param>
        /// <returns></returns>
        string Encrypt(string plaintext);

        /// <summary>
        /// 解密数据
        /// </summary>
        /// <param name="ciphertext">密文</param>
        /// <param name="password">用于派生密钥的密码</param>
        /// <param name="salt">用于派生密钥的密钥salt</param>
        /// <param name="iterations">操作的迭代数</param>
        /// <remarks>salt 大小必须等于或大于 8 字节，并且迭代次数必须大于零。 建议的最小迭代次数为 1000</remarks>
        /// <returns></returns>
        byte[] Decrypt(byte[] ciphertext, byte[] password, byte[] salt, int iterations);

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="ciphertext">密文</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        string Decrypt(byte[] ciphertext, byte[] password);

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="ciphertext">密文</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        string Decrypt(string ciphertext, string password);

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="ciphertext">密文</param>
        /// <returns></returns>
        string Decrypt(string ciphertext);
    }

    /// <summary>
    /// 哈希算法枚举
    /// </summary>
    public enum HashAlgorithmEnum
    {
        MD5,
        SHA1,
        SHA256,
        SHA384,
        SHA512
    }
}